package ldkxingzhe.ldkxingzhedemo.bar;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;
import android.widget.ProgressBar;

import ldkxingzhe.ldkxingzhedemo.R;

/**
 * Created by xingzhe on 15/10/16.
 */
public class ProgressDemoActivity extends AppCompatActivity{
    private final String TAG = ProgressDemoActivity.class.getSimpleName();

    private int[] images = {R.drawable.adward_box_1,
            R.drawable.adward_box_2,
            R.drawable.adward_box_3,
            R.drawable.adward_box_4,
            R.drawable.adward_box_5
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_demo_activity);
        final ProgressBar progressBar = (ProgressBar)findViewById(R.id.progress_bar);
//        progressBar.setProgress(50);
        progressBar.setInterpolator(new AccelerateInterpolator());

        final ImageView imageView = (ImageView)findViewById(R.id.image);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ValueAnimator progressAnimator = ObjectAnimator.ofInt(progressBar,"progress",0,100);
                progressAnimator.setDuration(5000);
                progressAnimator.setInterpolator(new AccelerateInterpolator());
                progressAnimator.setRepeatCount(ValueAnimator.INFINITE);
                progressAnimator.setRepeatMode(ValueAnimator.RESTART);
                progressAnimator.start();
            }
        });
    }
}
